<template>
  <tl-sub-page :render="render" ref="drawerRef" :visible.sync="visible" :with-header="false" :modal-append-to-body="true" :close-on-press-escape="false" :append-to-body="true" class="tl-drawer" :size="'95%'" @open="open" @close="close" :destroy-on-close="true">
    <div class="mpm-project-container">
      <div style="width:0px;overflow:hidden;height:0px;"><input type="text" /></div>
      <div class="mpm-project-header">
        <div class="info">
          <img src="/static/images/paojectManager/mpm_supervise_round.png" class="logo" style="width: 55px;height: 55px" />
          <div class="content" :title="model.projectname">
            <p class="displaychange" v-show="model.projectname">
              <b>{{ model.projectname + '-' }}</b>
              <b>项目督办</b>
            </p>
            <p class="light" v-show="model.projectmanager">
              <span>项目经理：{{ model.projectmanager + '【' + model.projectmanagercode + '】' }}</span>
              <span>创建时间：{{ formatDate(model.createon) }}</span>
            </p>
          </div>
        </div>
        <div class="toolbar">
          <el-button type="danger" icon="el-icon-close" circle @click="doCancelEdit"></el-button>
        </div>
      </div>
      <div class="mpm-project-main" :style="{ height: mainHeight + 'px' }">
        <el-scrollbar class="mpm-project-main-container" id="mpmMainContainer">
          <div style="padding:0 20px">
            <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px">
              <div class="tl-form-line-title">
                基本信息
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="督办单名称" prop="supervisename" :rules="rules.validateRequire">
                    <el-input v-model="model.supervisename"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办单类型" prop="supervisetype" :rules="rules.validateRequire">
                    <el-select v-model="model.supervisetype" filterable clearable @change="changesupervisetype">
                      <el-option v-for="item in codeModel.supervisetypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办单编号" prop="supervisecode" v-show="false">
                    <el-input v-model="model.supervisecode" :disabled="true" placeholder="系统自动赋值"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="督办对象大类" prop="superviseobjecttype" :rules="rules.validateRequire">
                    <el-select v-model="model.superviseobjecttype" filterable clearable @change="changesuperviseobjecttype" :disabled="!Boolean(model.supervisetype)" multiple>
                    <!-- <el-select v-model="model.superviseobjecttype" filterable clearable @change="changesuperviseobjecttype"> -->
                      <el-option v-for="item in computedBigtype" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="12">
          <el-form-item label="督办对象" prop="superviseobject">
            <el-input v-model="model.superviseobject"></el-input>
          </el-form-item>
        </el-col> -->
                <el-col :span="12">
                  <el-form-item label="督办对象小类" prop="superviseobject" :rules="rules.validateRequire" v-if="showMilepostObject">
                    <el-input v-model="model.superviseobject" :disabled="true" class="tl-ref-selector" :class="{ disabled: dodisabled }">
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectMilepostDialog" :disabled="dodisabled"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办对象小类" prop="superviseobject" :rules="rules.validateRequire" v-if="showTextObject">
                    <el-input v-model="model.superviseobject" :disabled=" !model.superviseobjecttype || !model.superviseobjecttype === '0'" class="tl-ref-selector" :class="{ disabled: dodisabled }"> </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办对象小类" prop="superviseobject" :rules="rules.validateRequire" v-if="showTaskObject">
                    <el-input v-model="model.superviseobject" disabled class="tl-ref-selector" :class="{ disabled: dodisabled }">
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectTaskDialog" :disabled="dodisabled"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办对象小类" prop="superviseobject" :rules="rules.validateRequire" v-if="showHistoryObject">
                    <el-input v-model="model.superviseobject" class="tl-ref-selector" :class="{ disabled: dodisabled }" v-if="model.supervisetype"> </el-input>
                    <el-select v-model="model.superviseobject" filterable :disabled="!Boolean(model.supervisetype)" clearable v-else >
                      <el-option v-for="item in codeModel.superviseobjectList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办对象小类" prop="superviseobject" :rules="rules.validateRequire" v-if="showMeetObject">
                    <el-select v-model="model.superviseobject" filterable clearable>
                      <el-option v-for="item in codeModel.meettypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办对象小类" prop="superviseobject" :rules="rules.validateRequire" v-if="showBidScoreObject">
                    <el-select v-model="model.superviseobject" filterable clearable>
                      <el-option v-for="item in codeModel.bidsourcetypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="责任人" prop="responsiblecode" :rules="rules.validateRequire">
                    <tl-ref-user v-model="model.responsiblecode" :initDisplayData.sync="model.responsiblename" dataType="code" :singleSelect="true" @confirm="userConfirm"></tl-ref-user>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办期限" prop="superviseperiod">
                    <el-date-picker v-model="model.superviseperiod" type="date" value-format="yyyy-MM-dd" :picker-options="pickerOptions"></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="督办原因" prop="supervisereason" :rules="rules.validateRequire">
                    <el-input v-model="model.supervisereason" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="model.superviseresponse">
                  <el-form-item label="督办响应" prop="superviseresponse">
                    <el-input v-model="model.superviseresponse" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="督办发起部门" prop="supervisedeptname">
                    <el-input v-model="model.supervisedeptname" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="督办发起人" prop="supervisepeople">
                    <el-input v-model="model.supervisepeople" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="督办状态" prop="supervisestate">
                    <el-select v-model="model.supervisestate" filterable clearable :disabled="true">
                      <el-option v-for="item in codeModel.supervisestateList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="抄送范围" prop="responsiblecode">
                    <tl-ref-user v-model="model.ccstaffcode" :initDisplayData.sync="model.ccstaffname" dataType="code" :singleSelect="false" @confirm="staffConfirm"></tl-ref-user>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="备注" prop="description">
                    <el-input v-model="model.description" type="textarea" maxlength="1000" show-word-limit :rows="4"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-collapse>
                <el-collapse-item title="【单据】申请信息">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="申请部门" prop="applydeptname">
                        <tl-ref-dept v-model="model.applydeptcode" :initDisplayData.sync="model.applydeptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true" :externalQueryParam="{ qry_enabled: 1 }"></tl-ref-dept>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="申请公司" prop="applyorgname">
                        <el-input v-model="model.applyorgname" :readonly="true" class="is-disabled"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="申请人姓名" prop="applyusername">
                        <tl-ref-user v-model="model.applyusername" :initDisplayData.sync="model.applyusername" :disabled="true" dataType="code" :singleSelect="true"></tl-ref-user>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="申请人工号" prop="applyusercode">
                        <el-input v-model="model.applyusercode" :readonly="true" class="is-disabled"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="单据日期" prop="docdate">
                        <el-date-picker v-model="model.docdate" type="date" :disabled="true" placeholder="单据日期" value-format="yyyy-MM-dd"></el-date-picker>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-collapse-item>
              </el-collapse>
            </el-form>
            <div slot="footer" class="dialog-footer" style="float: right; margin-top: 10px">
              <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" icon="el-icon-document-checked">保存</el-button>
              <tl-attachment ref="attachmentRef" sourceType="MpmProjectSupervise" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit" :extendData="fileParam">
                <el-button type="primary" :disabled="disableAttachment" icon="el-icon-paperclip" @click="$refs.attachmentRef.openUploadDialog()"> {{ this.$refs.attachmentRef ? this.$refs.attachmentRef.btnTitle : '' }} [{{ this.$refs.attachmentRef ? (this.$refs.attachmentRef.fileList.length > 0 ? this.$refs.attachmentRef.fileList.length : this.$refs.attachmentRef.fileCount) : 0 }}] </el-button>
              </tl-attachment>
              <tl-attachment ref="attachmentResponseRef" sourceType="MpmProjectSuperviseResponse" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit&&model.state!==0&&model.state!==2" :btnTitle="'反馈附件'" :extendData="fileParam">
                <el-button type="primary" :disabled="disableAttachment" icon="el-icon-paperclip" @click="$refs.attachmentResponseRef.openUploadDialog()"> {{ this.$refs.attachmentResponseRef ? this.$refs.attachmentResponseRef.btnTitle : '' }} [{{ this.$refs.attachmentResponseRef ? (this.$refs.attachmentResponseRef.fileList.length > 0 ? this.$refs.attachmentResponseRef.fileList.length : this.$refs.attachmentResponseRef.fileCount) : 0 }}] </el-button>
              </tl-attachment>
              <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory">
                <svg-icon icon-class="list" />审批历史
              </el-button>
            </div>
          </div>
        </el-scrollbar>
      </div>
      <tl-approval-history ref="history" sourceType="MpmProjectSupervise" :sourceId="model.id" />
      <tlmpmProject-milepost-ref ref="mpmProjectMilepostRef" @confirm="getMpmProjectMilepostData" :isSingleSelect="true" :externalQueryParam="externalQueryParamForMilepost"> </tlmpmProject-milepost-ref>
      <tlmpmProject-task-ref ref="mpmProjectTaskRef" @confirm="getMpmProjectTaskData" :isSingleSelect="true" :externalQueryParam="externalQueryParamForTask"> </tlmpmProject-task-ref>
    </div>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import tlmpmProjectMilepostRef from '@/views/mpm/mpmProjectMilepost/refList'
import tlmpmProjectTaskRef from '@/views/mpm/mpmProjectTask/refList'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import { formatDate } from '@tapui/utils/date'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { tlmpmProjectMilepostRef, tlmpmProjectTaskRef },
  data() {
    return {
      moduleTitle: '项目督办',
      urlPrefix: '/mpm/projectSupervise/',
      // 进度对应编码
      progressArray: ['0', '3', '4', '5', '1', '2', '6', '7', '8', '9'],
      qualityArray: ['0', '10', '11', '12', '13', '14', '15', '16', '17'],
      // 赋值项目名称和项目经理的大类
      classProject: ['3', '4', '5', '1', '9', '10', '11', '12', '17'],
      // 里程碑处理
      classMilepost: ['2', '13'],
      // 任务处理
      classTask: ['6', '14'],
      // 自评处理
      classBidSource: ['7', '15'],
      // 会议处理
      classMeet: ['8', '16'],
      fileParam: {},
      taskvisible: false,
      externalQueryParamForTask: {},
      externalQueryParamForMilepost: {},
      mainHeight: 100,
      url: {
        // 额外的url
        updateSuperviseUser: '/mpm/projectSupervise/updateSuperviseUser'
      },
      fromApproval: '',
      pickerOptions: {
        // disabledDate是一个函数,参数是当前选中的日期值,这个函数需要返回一个Boolean值,
        disabledDate: (time) => {
          // 禁用今天之前的日期选择
          let date = new Date()
          date.setHours(0, 0, 0, 0)
          return time.getTime() < date.getTime()
        }
      }
    }
  },
  props: {
    render: {
      default: 'el-drawer',
      type: String
    },
    projectinfo: {}
  },
  computed: {
    dodisabled() {
      return (this.isAdd === false && this.disableEditSubmit === true) || this.fromApproval === '1'
    },
    computedBigtype() {
      if (!this.model.supervisetype) {
        return this.codeModel.superviseobjecttypeList
      } else if (this.model.supervisetype === '0') {
        // 进度对应
        return this.codeModel.superviseobjecttypeList.filter((item) => this.progressArray.includes(item.code))
      } else {
        // 质量对应
        return this.codeModel.superviseobjecttypeList.filter((item) => this.qualityArray.includes(item.code))
      }
    },
    showTextObject() {
      return !(this.showHistoryObject || this.showMilepostObject || this.showTaskObject || this.showBidScoreObject || this.showMeetObject)
    },
    showHistoryObject() {
      if (!Array.isArray(this.model.superviseobjecttype) || this.model.superviseobjecttype.length !== 1) {
        return false
      }
      let temp = this.model.superviseobjecttype[0]
      if (temp === '0' && !this.model.supervisetype) {
        return true
      }
      return false
    },
    showMilepostObject() {
      if (!Array.isArray(this.model.superviseobjecttype) || this.model.superviseobjecttype.length !== 1) {
        return false
      }
      let temp = this.model.superviseobjecttype[0]
      if (this.classMilepost.includes(temp)) {
        return true
      }
      return false
    },
    showTaskObject() {
      if (!Array.isArray(this.model.superviseobjecttype) || this.model.superviseobjecttype.length !== 1) {
        return false
      }
      let temp = this.model.superviseobjecttype[0]
      if (this.classTask.includes(temp)) {
        return true
      }
      return false
    },
    showBidScoreObject() {
      if (!Array.isArray(this.model.superviseobjecttype) || this.model.superviseobjecttype.length !== 1) {
        return false
      }
      let temp = this.model.superviseobjecttype[0]
      if (this.classBidSource.includes(temp)) {
        return true
      }
      return false
    },
    showMeetObject() {
      if (!Array.isArray(this.model.superviseobjecttype) || this.model.superviseobjecttype.length !== 1) {
        return false
      }
      let temp = this.model.superviseobjecttype[0]
      if (this.classMeet.includes(temp)) {
        return true
      }
      return false
    }
  },
  methods: {
    /** 抽屉组件必有 **/
    resizeHandler() {
      this.mainHeight = document.body.getBoundingClientRect().height - 100 - (this.isApproval ? 110 : 0)
    },
    /** 页面打开时执行 - zhanglongfei 2019.10.18 */
    open() {
      this.resizeHandler()
      this.model = {}
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '添加' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.$refs.form.clearValidate()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化
            this.$set(this.model, 'enabled', 1)
            this.$set(this.model, 'sortcode', 0)
            this.assignDefaultValue()
            this.$refs.form.clearValidate()
            this.loaded()
          }
        } else if (this.disableEditSubmit === false) {
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.loaded()
          })
        } else {
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.$refs.form.clearValidate()
            this.loaded()
          })
        }
      })
    },
    formatDate(date) {
      return formatDate(new Date(date ? date.toString().replace(/\-/g, "/") : date), "yyyy-MM-dd")
    },
    changesupervisetype() {
      // 清除垃圾数据
      this.$set(this.model, 'superviseobjecttype', '')
      this.$set(this.model, 'superviseobject', '')
      this.$set(this.model, 'superviseobjectcode', '')
      this.$set(this.model, 'responsiblecode', '')
      this.$set(this.model, 'responsiblename', '')
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
    },
    changesuperviseobjecttype(e) {
      // 清除垃圾数据
      this.$set(this.model, 'superviseobject', '')
      this.$set(this.model, 'superviseobjectcode', '')
      this.$set(this.model, 'responsiblecode', '')
      this.$set(this.model, 'responsiblename', '')
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
      if (e.length === 1) {
        let bigTypeStr = e[0]
        if (bigTypeStr === '0') {
          this.$set(this.model, 'superviseobjectcode', this.projectinfo.projectcode)
        } else if (this.classProject.includes(bigTypeStr)) {
          // 项目等
          this.$set(this.model, 'superviseobject', this.model.projectname)
          this.$set(this.model, 'responsiblecode', this.projectinfo.projectmanagercode)
          this.$set(this.model, 'responsiblename', this.projectinfo.projectmanager)
        } else if (this.classBidSource.includes(bigTypeStr)) {
          // 评分细则
          this.$set(this.model, 'responsiblecode', this.projectinfo.projectmanagercode)
          this.$set(this.model, 'responsiblename', this.projectinfo.projectmanager)
        } else if (this.classMeet.includes(bigTypeStr)) {
          // 会议
          this.$set(this.model, 'responsiblecode', this.projectinfo.projectmanagercode)
          this.$set(this.model, 'responsiblename', this.projectinfo.projectmanager)
        }
      }
    },
    /** 打开里程碑及任务参照 */
    openMpmProjectMilepostDialog() {
      if (this.model.superviseobjecttype === '' || this.model.superviseobjecttype === undefined) {
        this.$tap.alert('请先选择督办对象类型', 'warning')
        return
      }
      const { projectcode } = this.projectinfo
      this.externalQueryParamForMilepost = {
        qry_projectcode: projectcode,
        qry_enabled: 1,
        qry_milepoststate: 0
      }
      this.$refs.mpmProjectMilepostRef.visible = true
    },
    /** 获取里程碑及任务参照数据 */
    getMpmProjectMilepostData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'superviseobject', selectionRow.milepostname)
      this.$set(this.model, 'superviseobjectcode', selectionRow.milepostcode)
      // 里程碑及任务赋值责任人
      this.$set(this.model, 'responsiblecode', selectionRow.responsiblecode)
      this.$set(this.model, 'responsiblename', selectionRow.responsible)
    },
    /** 打开任务参照 */
    openMpmProjectTaskDialog() {
      const { projectcode } = this.projectinfo
      this.externalQueryParamForTask = {
        qry_projectcode: projectcode,
        qry_enabled: 1,
        qry_taskstate: '0,1'
      }
      this.$refs.mpmProjectTaskRef.visible = true
    },
    /** 获取任务参照数据 */
    getMpmProjectTaskData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'superviseobject', selectionRow.taskname)
      this.$set(this.model, 'superviseobjectcode', selectionRow.taskcode)
      // 赋值任务责任人
      this.$set(this.model, 'responsiblecode', selectionRow.responsiblecode)
      this.$set(this.model, 'responsiblename', selectionRow.responsible)
    },
    staffConfirm(selectionRow) {
      if (!Array.isArray(selectionRow)) {
        this.$set(this.model, 'ccstaffcode', selectionRow[0].code)
        this.$set(this.model, 'ccstaffname', selectionRow[0].name)
      } else {
        let tempname = ''
        let tempcode = ''
        selectionRow.forEach((item, index) => {
          this.$set(this.model, 'ccstaffcode', item.code)
          this.$set(this.model, 'ccstaffname', item.name)
          if (tempname.length > 0) {
            tempname = tempname + '，' + item.name
            tempcode = tempcode + ',' + item.code
          } else {
            tempname = item.name
            tempcode = item.code
          }
        })
        this.$set(this.model, 'ccstaffcode', tempcode)
        this.$set(this.model, 'ccstaffname', tempname)
      }
    },
    // 督办部门从一级部门显示
    onelevelDeptname(deptName) {
      if (!deptName) {
        return
      }
      if (deptName.indexOf('鼎信股份') !== -1) {
        let num
        num = deptName.indexOf('\\') + 1
        return deptName.substring(num)
      } else {
        return deptName
      }
    },
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
          this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
        }
        let a = this.projectinfo
        this.$set(this.model, 'createon', this.projectinfo.createon)
        this.$set(this.model, 'projectmanager', this.projectinfo.projectmanager)
        this.$set(this.model, 'projectmanagercode', this.projectinfo.projectmanagercode)
        this.$set(this.model, 'projectname', this.projectinfo.projectname)
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'disporgcode', this.org.name)
        this.$set(this.model, 'applyorgcode', this.org.code)
        this.$set(this.model, 'applyorgname', this.org.name)
        this.$set(this.model, 'applydeptcode', this.dept.code)
        this.$set(this.model, 'applydeptname', this.dept.fullname)
        // 默认为其他
        this.$set(this.model, 'superviseobjecttype', '0')
        // 赋值部门信息(赋值项目上的)
        this.$set(this.model, 'deptcode', this.projectinfo.deptcode)
        this.$set(this.model, 'deptname', this.projectinfo.deptname)
        // 赋值项目信息
        this.$set(this.model, 'projectcode', this.projectinfo.projectcode)
        this.$set(this.model, 'projectname', this.projectinfo.projectname)
        // 督办部门信息
        this.$set(this.model, 'supervisedeptcode', this.dept.code)
        this.$set(this.model, 'supervisedeptname', this.onelevelDeptname(this.dept.fullname))
        // 督办发起人信息
        this.$set(this.model, 'supervisepeoplecode', this.user.code)
        this.$set(this.model, 'supervisepeople', this.user.name)
        // 督办状态
        this.$set(this.model, 'supervisestate', '0')
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'applyusercode', this.user.code)
        this.$set(this.model, 'applyusername', this.user.name)
        this.$set(this.model, 'docdate', new Date())
        // 督办期限为3天
        var date = new Date()
        date.setDate(date.getDate() + 3)
        this.$set(this.model, 'superviseperiod', date)
      }
    },
    // 办理通过前保存修改的信息
    saveInfo(resolve, reject) {
      // 修改督办审批人员信息
      this.$set(this.model, 'applyusercode', this.user.code)
      this.$set(this.model, 'applyusername', this.user.name)
      this.$set(this.model, 'usercode', this.user.code)
      this.$set(this.model, 'username', this.user.name)
      this.$set(this.model, 'supervisepeoplecode', this.user.code)
      this.$set(this.model, 'supervisepeople', this.user.name)
      if (Array.isArray(this.model.superviseobjecttype)) {
        this.$set(this.model, 'superviseobjecttype', this.model.superviseobjecttype.join(','))
      }
      putAction(this.url.updateSuperviseUser, this.model)
        .then((res) => {
          if (res.success) {
            this.model.superviseobjecttype && !Array.isArray(this.model.superviseobjecttype) ? this.$set(this.model, 'superviseobjecttype', this.model.superviseobjecttype.split(',')) : null
            resolve()
          } else {
            this.$tap.alert(res.message, 'warning')
            this.model.superviseobjecttype && !Array.isArray(this.model.superviseobjecttype) ? this.$set(this.model, 'superviseobjecttype', this.model.superviseobjecttype.split(',')) : null
            reject()
          }
        })
        .catch((err) => {
          this.$tap.alert('保存审批类型信息失败，请联系系统管理员', 'warning')
          this.model.superviseobjecttype && !Array.isArray(this.model.superviseobjecttype) ? this.$set(this.model, 'superviseobjecttype', this.model.superviseobjecttype.split(',')) : null
          reject()
        })
    },
    loaded() {
      this.resizeHandler()
      // 页面加载完毕执行
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
        this.$set(this.model, 'supervisedeptname', this.onelevelDeptname(this.model.supervisedeptname))
      }
      // 获取审批参数
      this.$nextTick((_) => {
        let approvalparam = this.approvalNodeModel.approvalparam
        let approvalparamobject = JSON.parse(approvalparam)
        this.extraParam = approvalparamobject ? approvalparamobject.extraParam : ''
        if (this.extraParam === 'Owner') {
          this.$nextTick(() => {
            this.$refs.dealform.clearValidate()
          })
        }
      })
    },
    userConfirm(selectionRow) {
      this.$set(this.model, 'responsiblecode', selectionRow[0].code)
      this.$set(this.model, 'responsiblename', selectionRow[0].name)
    },
    doCancelEdit() {
      this.visible = false
      this.$emit('close')
      this.$emit('refresh')
    },
    /** 编辑，发请求获得数据 */
    queryData(id) {
      if (!this.url.load) {
        this.$tap.alert('请设置load地址!', 'warning')
        return
      }
      return getAction(this.url.load, { id: id }).then((res) => {
        if (res.success) {
          this.model = res.result
          this.model.superviseobjecttype && !Array.isArray(this.model.superviseobjecttype) ? this.$set(this.model, 'superviseobjecttype', this.model.superviseobjecttype.split(',')) : null
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    }
  },
  // watch: {
  //   model(newValue, oldValue) {
  //       if(newValue.changesuperviseobjecttype)
  //   }
  // }
  created() {
    // 抽屉组件必有
    window.addEventListener('resize', this.resizeHandler)
  },
  destroyed() {
    // 抽屉组件必有
    window.removeEventListener('resize', this.resizeHandler)
  }
}
</script>
<style scoped></style>
